package tool.data;

import tool.analysis.IVariableAndParameterAnalyser;
import japa.parser.ast.body.ModifierSet;

	/**
	 * @author jwb09119
	 * @date 2013/11/22
	 * 
	 * This class represents a parsed variable from Java source code.  It is a data wrapper, but has
	 * high semantic cohesion.
	 * 
	 * This was formerly a inner class of VariableVisitor, pulled out as the class was getting
	 * too crowded.
	 */

public class FieldRecord {
	
	public static enum EScope {
    	CLASS, METHOD;
    }
    
	private String name;
	private TypeDefinition type;
	private boolean isArray;
	private int modifiers;
	private EScope scope;

	
	public FieldRecord(String name, TypeDefinition type, EScope scope) {

       this.name = name;
       this.type = type;
       this.scope = scope;
    }


    public String getName() {
		
		return new String(name);
		
	}

	
	public String getFullTypeName() {
		
		return type.getNameWithPath();
		
	}


	public boolean isArray() {
		
		return isArray;
		
	}

	
	public void setIsArray (boolean isArray) {
		
		this.isArray = isArray;
		
	}

	
	public int getModifiers() {
		
		return modifiers;
		
	}

	
	public void setModifiers(int modifiers) {
		
		this.modifiers = modifiers;
		
	}
	
	
	public boolean isStatic () {
		
		return ModifierSet.isStatic(getModifiers());
		
	}
	
	
	public boolean isPrivate () {
		
		return ModifierSet.isPrivate(getModifiers());
		
	}
	
	
	public boolean isFinal () {
		
		return ModifierSet.isFinal(getModifiers());
		
	}
	
	
	public boolean isClassVariable () {
		
		return scope == EScope.CLASS;
		
	}
	
	
	public boolean isMethodVariable () {
		
		return scope == EScope.METHOD;
		
	}
	
	
	public EScope getScope () {
		
		return scope;
		
	}

	
	@Override
	public String toString () {
		
		return "\nField:\nName: "+getName()+"\nType: "+getFullTypeName()+"\nIs Array: "+isArray()+"\nScope: "
				+ scope + "\nModifers: "+ (isStatic() ? "static " : "") + 
				(isPrivate() ? "private " : "") + (isFinal() ? "final " : "");	
		
	}
	
	
	public void accept (IVariableAndParameterAnalyser visitor) {
        
        visitor.visit(this);
        
    }
	
}
